﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Threading;

namespace Testy {
	class AsyncServer {
		public static ManualResetEvent clientConnected = new ManualResetEvent(false);
		public static void Main() {
			TcpListener tcpl = new TcpListener(IPAddress.Parse("127.0.0.1"), 9000);
			tcpl.Start();
			tcpl.BeginAcceptSocket(new AsyncCallback(DoAcceptSocketCallback), tcpl);
			TcpClient client = new TcpClient("localhost", 9000);
			clientConnected.WaitOne();
			Console.WriteLine("No a teraz to już wypisał o tym kolesiu");
			clientConnected.Reset();
			clientConnected.WaitOne(1000, true);
		}
		public static void DoAcceptSocketCallback(IAsyncResult ar)
		{
			var tcpListener = ar.AsyncState as TcpListener;
			Console.WriteLine("koles sie zalogował");
			clientConnected.Set();
		}
	}
}
